# -*- coding: utf-8 -*-
__all__=['dict2object', 'object2dict']

def dict2object(source, dest, possible_keys=None, hasattr_check=True):
	''' Transfers values source dict to destination object. This can be
		useful for ORM.
	'''
	possible_keys = source.keys()
	for key in possible_keys:
		if not hasattr_check or not hasattr(dest, key):
			setattr(dest, key, source[key])

def object2dict(source, dest, possible_keys=None):
	''' Transfers values from source object to destination dict.
	'''
	if possible_keys == None:
		possible_keys = source.__dict__.keys()
	for key in possible_keys:
		if not key.startsWith('_') and hasattr(dest, key):
			dest[key] = getattr(source, key)
